package com.yanqu.road.server.cmd.minewar;

import com.yanqu.road.server.pb.MineWarPb;
import com.yanqu.road.entity.minewar.MineStationInfo;
import com.yanqu.road.pb.minewar.MineWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.server.manger.config.MineWarConfigMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Cmd(code = Protocol.S_MINE_WAR_STATION_SIMPLE, desc = "矿站简略信息")
public class MineStationSimpleCmd extends AbstractCommand {

	private int mineType;

	private List<MineStationInfo> stationInfoList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		MineWarProto.MineGetStationSimpleReqMsg reqMsg = MineWarProto.MineGetStationSimpleReqMsg.parseFrom(packet.getBytes());
		mineType = reqMsg.getMineType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(player.getTitleId() < ConfigMgr.getMineOpenNeedTitle(mineType)){
			return;
		}
		Map<Integer, MineStationInfo> mineStationInfoMap = MineWarConfigMgr.getMineStationMapByType(mineType);
		if(null != mineStationInfoMap){
			stationInfoList = new ArrayList<>(mineStationInfoMap.values());
		}

	}

	@Override
	public void sendData(GamePlayer player) {
		MineWarProto.MineStationListMsg.Builder respMsg = MineWarPb.parseMineStationListMsg(stationInfoList);
		player.sendPacket(Protocol.U_MINE_WAR_STATION_SIMPLE, respMsg);
	}
}
